<template>
  <div class="prescription-print-view" v-if="patientData">
    <!-- 检查治疗项打印 -->
    <div class="print-main" style="padding: 20px; page-break-after: always">
      <prescription-header
        titles="诊疗费用单"
        :types="2"
        :patientData="patientData"
      ></prescription-header>
      <div class="prescription-container">
        <check-item-list
          :checkList="checkItemList"
          :surchargeList="surchargeList"
        ></check-item-list>
      </div>
      <prescription-footer :patientData="checkItemFooter"></prescription-footer>
    </div>
  </div>
</template>
<script>
import prescriptionHeader from "./prescriptionHeader.vue";
import prescriptionFooter from "./prescriptionFooter.vue";
import checkItemList from "./checkItemList.vue";
export default {
  components: {
    prescriptionHeader,
    prescriptionFooter,
    checkItemList,
  },
  props: {
    patientData: {
      type: Object,
      default: () => {},
    },
    printItemData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      checkItemList: [],
      checkItemFooter: {},
      surchargeList: [],
    };
  },
  watch: {
    patientData: {
      handler(newval, oldval) {
        if (newval) {
          this.checkItemFooter = {
            doctor_name: newval.doctor_name,
            amount: 0,
          };
          if (!Array.isArray(newval.age)) {
            newval.age = newval.age.split(",").map((value) => {
              return Number(value);
            });
          }
        }
      },
      immediate: true,
    },
    printItemData: {
      handler(newval, oldval) {
        if (newval) {
          this.checkItemFooter.amount = newval.amount
          if (newval.type == 1) {
            this.checkItemList = [];
            this.checkItemList.push(newval);
          } else if (newval.type == 2) {
            this.surchargeList = [];
            this.surchargeList.push(newval);
          }
        }
      },
      immediate: true
    },
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
@import "@/assets/scss/print/prescriptionPrint.scss";
</style>